﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Ample;
using Ample.BLL;

/// <summary>
/// Summary description for BasePage
/// </summary>
public class BasePage : System.Web.UI.Page
{
    protected override void OnPreInit(EventArgs e)
    {
        if ((HttpContext.Current.Profile as ProfileCommon).ShoppingCart == null)
            (HttpContext.Current.Profile as ProfileCommon).ShoppingCart = new Ample.BLL.Store.ShoppingCartBO();

        base.OnPreInit(e);
    }

    public string BaseUrl
    {
        get
        {
            string url = this.Request.ApplicationPath;
            if (url.EndsWith("/"))
                return url;
            else
                return url + "/";
        }
    }

    public string FullBaseUrl
    {
        get
        {
            return this.Request.Url.AbsoluteUri.Replace(
               this.Request.Url.PathAndQuery, "") + this.BaseUrl;
        }
    }

    protected void RequestLogin()
    {
        this.Response.Redirect(FormsAuthentication.LoginUrl +
           "?ReturnUrl=" + this.Request.Url.PathAndQuery);
    }

    public string FormatPrice(object price)
    {
        return Convert.ToDecimal(price).ToString("N2") + " " + Globals.Settings.Store.CurrencyCode;
    }
}
